$(function () {
    getnew();
    let id = null;
    function getnew() {
        $.ajax({
            url: "http://124.223.14.236:8060/user/getUserInfo",
            headers: {
                token: localStorage.getItem("token") || "",
            },
            success: function (res) {
                console.log(res);
                id = res.data.userInfo.id;
            },
        });
    }

    // 监听用户上传头像
    $("#img").on("click", function () {
        // alert(1111)
        $("#hipt").click();
    });
    // 用户头像()
    $("#hipt").on("change", function (e) {
        let files = e.target.files;
        let imgurl = URL.createObjectURL(files[0]);
        $("#img").attr("src", imgurl);
    });

    // 提交修改数据
    $("#xiugai").on("click", function () {
        $.ajax({
            url: "http://124.223.14.236:8060/user/update",
            method: "post",
            headers: {
                token: localStorage.getItem("token"),
            },
            data: {
                mobile: $("#p").val(),
                icon: $("#img").attr("src"),
                username: $("#n").val(),
                sex: $("#s").val(),
                birthday: $("#n").val(),
                address: $("#d").val(),
                notes: $("#t").val(),
                id: id,
            },
            success: function (res) {
                if (res.errno != 0) {
                    return alert(res.errmsg);
                }
                alert("成功");
            },
        });
    });
})